import {useLocation, useNavigate, useParams, useSearchParams} from "react-router-dom";

function WithRouter(WrapperComponent) {
    return function NewComponent(props) {
        // 导航
        const navigate = useNavigate();

        // 动态路由参数 /detail/:id
        const params = useParams();

        // 查询字符串参数 /user?name=zc&age=18
        const location = useLocation();

        const [URLSearchParams] = useSearchParams();
        const query = Object.fromEntries(URLSearchParams);

        const router = {navigate, params, location, query}

        return (
            <WrapperComponent {...props} router={router}/>
        )
    }
}

export default WithRouter;